package com.lj.sys.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lj.common_web.annotation.ResponseResultVo;
import com.lj.common_web.utils.ServletUtil;
import com.lj.sys.param.SysLogPageParam;
import com.lj.sys.result.SysLogInfoResult;
import com.lj.sys.result.SysLogPageResult;
import com.lj.sys.service.SysLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * <p>
 * 系统日志 前端控制器
 * </p>
 *
 * @author luojing
 * @since 2025-04-18 17:22:24
 */
@RestController
@RequestMapping("/sys/sys_log")
@ResponseResultVo
@Tag(name = "系统日志 管理")
public class SysLogController {

    @Resource
    private SysLogService sysLogService;

    @GetMapping("/page")
    @SaCheckPermission("sys:sys_log:list")
    @Operation(summary = "系统日志 分页查询")
    public IPage<SysLogPageResult> page(@ParameterObject SysLogPageParam param) {
        return sysLogService.page(param);
    }

    @GetMapping("/info/{id}")
    @SaCheckPermission("sys:sys_log:info")
    @Operation(summary = "系统日志 信息")
    public SysLogInfoResult info(@PathVariable("id") @Parameter(name = "id", description = "系统日志 id") Long id) {
        if (id == null) {
            return null;
        }
        return sysLogService.info(id);
    }

    @GetMapping("/export/excel")
    @SaCheckPermission("sys:sys_log:list")
    @Operation(summary = "系统日志 excel导出")
    public void exportExcel(@ParameterObject SysLogPageParam param) throws IOException {
        ServletUtil.download("系统日志-导出数据.xlsx",
                outputStream -> sysLogService.exportExcel(param, outputStream));
    }

}

